import axios from 'axios'
import nProgress from 'nprogress'
import '../../node_modules/nprogress/nprogress.css'

const request = axios.create({
    baseURL: '/api',
    timeout: 5000

})

request.interceptors.request.use((config) => {
    nProgress.start()
    return config
})

request.interceptors.response.use(
    (res) => {
        nProgress.done()
        return res.data
    },
    (err) => {
        const status =err.response.status
        switch (status) {
            case 404:
                alert('请求资源不存在')
                break;
            case 500:
                alert('服务器资源不存在')
                break;
            case 403:
                alert('请求资源被拒绝')
                break;
        }
        return  new Promise((resolve, reject) => {
            
        })
    }
)

export default request